areas_array=newArray();//set up empty arrays for values from all images

label_array=newArray();

filename_array=newArray();


dir1=getDirectory("Choose Directory");//Set source directory

files=getFileList(dir1);//list the files in the directory


for (i = 0; i < files.length; i++) {//Create a loop with as many iterations as there are filenames

path=dir1+files[i];//joing file name and directory to make a complete path

open(path);//open file using the path

rename("Original");//rename to give uniform names to each open image

run("Stack to Images");//Split the stack into individual images

selectWindow("Original-0001");//select channel 1 (DAPI)


//Segment with Stardist

run("Command From Macro", "command=[de.csbdresden.stardist.StarDist2D], args=['input':'Original-0001', 'modelChoice':'Versatile (fluorescent nuclei)', 'normalizeInput':'true', 'percentileBottom':'1.0', 'percentileTop':'99.8', 'probThresh':'0.5', 'nmsThresh':'0.4', 'outputType':'Both', 'nTiles':'1', 'excludeBoundary':'2', 'roiPosition':'Automatic', 'verbose':'false', 'showCsbdeepProgress':'false', 'showProbAndDist':'false'], process=[false]");


run("Analyze Regions", "area");//Calculate areas

area=Table.getColumn("Area");//assign area values to variable

label=Table.getColumn("Label");//assign label values to variable


//concatinate image variables to an an array for all the images

areas_array=Array.concat(areas_array,area);//concatinate image variables to an an array for all the images

label_array=Array.concat(label_array,label);


for (j = 0; j < area.length; j++) {//loop adding image filename to the filename_array once for every label measured

filename_array=Array.concat(filename_array,files[i]);

}


close("Label-Morphometry");//close image results table

close("*");//close all images

}


Table.showArrays("Areas_Table", filename_array, label_array, areas_array); //compose a results table with all the areas